/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.dao;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.jrose.core.jdbc.persistence.support.DatabaseConnectionProvider;
import org.jrose.dao.jdbc.AttributePersistence;
import org.jrose.dao.jdbc.RoleCareerPersistence;
import org.jrose.dao.jdbc.RolePersistence;
import org.jrose.dao.jdbc.TeamLineupPersistence;
import org.jrose.dao.jdbc.TeamPersistence;
import org.jrose.dao.jdbc.UserPersistence;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

import javax.inject.Inject;
import javax.sql.DataSource;

/**
 * For providing all database access features.
 *
 * @author Xiaohai Zhang
 * @since 2013-08-25 01:49
 */
@NoArgsConstructor(access = AccessLevel.PROTECTED)
abstract public class DatabaseAccessProvider extends DatabaseConnectionProvider {
    protected DataSource dataSource;
    protected JdbcTemplate jdbcTemplate;
    protected NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    protected PlatformTransactionManager transactionManager;
    protected TransactionTemplate transactionTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();

        dataSource = databaseConnection.getDataSource();
        jdbcTemplate = databaseConnection.getJdbcTemplate();
        namedParameterJdbcTemplate = databaseConnection.getNamedParameterJdbcTemplate();
        transactionManager = databaseConnection.getTransactionManager();
        transactionTemplate = databaseConnection.getTransactionTemplate();
    }

    @Inject @Getter protected AttributePersistence attributePersistence;
    @Inject @Getter protected RoleCareerPersistence roleCareerPersistence;
    @Inject @Getter protected RolePersistence rolePersistence;
    @Inject @Getter protected TeamLineupPersistence teamLineupPersistence;
    @Inject @Getter protected TeamPersistence teamPersistence;
    @Inject @Getter protected UserPersistence userPersistence;
}
